<template>
  <div class="params-view">
    <div class="tit">参数</div>
    <NodeTree class="node-tree" ref="nodeTreeRef" :data="current.params || []" @updateForm="handleUpdate" />
  </div>
</template>

<script lang="ts" setup>
import NodeTree from "mctp-platform/src/components/public/NodeTree/index.vue";
import type { TreeItem } from "@/api/adjust/index.d";
import { apiMap, type TypeKeys } from "../index";
import { ElMessage } from "element-plus";
// import { useAuthStore } from "@/store/modules/auth";
const authStore = {
  calibrationName: "开场校准管理器"
};
const props = withDefaults(defineProps<{ current: Partial<TreeItem>; currentKey: TypeKeys }>(), {
  current: () => ({}),
  currentKey: "antennafactor"
});
const handleUpdate = async () => {
  console.log("current.params", props.current.params);
  const { edit, editKey, addKey } = apiMap[props.currentKey];
  await edit!!(
    {
      [editKey || addKey]: props.current
    },
    { calibrationName: authStore.calibrationName }
  );
  ElMessage.success("参数更新成功");
};
</script>
<style scoped lang="scss">
.params-view {
  height: 100%;

  .tit {
    padding: 0 16px;
    font-weight: bold;
    height: 32px;
    line-height: 32px;
    background-color: #f4f4f4;
    border: 1px solid #eaeaea;
    border-bottom: 0;
  }

  .node-tree {
    height: calc(100% - 33px);
  }
}
</style>
